package com.softline.documentsmall.controller;

import com.softline.documentsmall.entity.DictionaryInfoVO;
import com.softline.documentsmall.entity.DictionaryVO;
import com.softline.documentsmall.ret.BusinessErrorEnum;
import com.softline.documentsmall.ret.ReturnVO;
import com.softline.documentsmall.ret.ReturnVOUtils;
import com.softline.documentsmall.service.TooLanuageSearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @Author wph
 * @Date 2020/12/29 14:40
 */
@Api(value = "多语种术语搜索相关接口", tags = {"多语种术语搜索相关接口"})
@RestController
@RequestMapping("/tooLanuage")
@CrossOrigin(allowCredentials = "true", allowedHeaders = "*")
public class TooLanuageSearchController {
    @Autowired
    TooLanuageSearchService tooLanuageSearchService;

    /**
     *有新接口,此接口弃用 多语种术语搜索,根据用户输入语言，进行模糊搜索，
     *
     * @param pageNo
     * @param pageSize
     * @param type
     * @param name
     * @return
     * @author wph
     */
    @Deprecated
    @ApiOperation(value = "多语种术语搜索", notes = "多语种术语搜索")
    @GetMapping(value = "/search")
    public ReturnVO tooLanguageSearch(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, @RequestParam(name = "type", defaultValue = "en") String type, @RequestParam(name = "name") String name) {
        List<DictionaryVO> dictionaryVOList = tooLanuageSearchService.tooLanguageSearch(pageNo, pageSize, type, name);
        if (ObjectUtils.isEmpty(dictionaryVOList)) {
            return ReturnVOUtils.businessFail(BusinessErrorEnum.FAIL);
        } else {
            return ReturnVOUtils.success(dictionaryVOList);
        }
    }

    /**
     *有新接口,此接口弃用 根据用户输入关键词,语种搜索论文、专利等信息进行列表展示
     *
     * @param pageNo
     * @param pageSize
     * @param type
     * @param name
     * @return
     * @author wph
     */
    @Deprecated
    @ApiOperation(value = "相关知识与语料库搜索", notes = "相关知识与语料库搜索")
    @GetMapping(value = "/infoSearch")
    public ReturnVO infoSearch(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "5") Integer pageSize, @RequestParam(name = "type", defaultValue = "en") String type, @RequestParam(name = "name") String name) {
        List<DictionaryInfoVO> dictionaryInfoVOS = tooLanuageSearchService.infoSearch(pageNo, pageSize, type, name);
        if (ObjectUtils.isEmpty(dictionaryInfoVOS)) {
            return ReturnVOUtils.businessFail(BusinessErrorEnum.FAIL);
        } else {
            return ReturnVOUtils.success(dictionaryInfoVOS);
        }
    }
}
